package com.example.administrator.printoutindemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.ShenpiResultActivity;
import com.example.administrator.printoutindemo.bean.ShenpifankuiListBean;
import com.example.administrator.printoutindemo.http.SPUtil;

import java.util.ArrayList;
import java.util.List;

public class ShenPiFankuiAdapter extends BaseAdapter {

    Context context;
    List<ShenpifankuiListBean> mlist = new ArrayList<>();
    LayoutInflater inflater;

    public ShenPiFankuiAdapter(Context context, List<ShenpifankuiListBean> mlist) {
        this.context = context;
        this.mlist = mlist;
        this.inflater = LayoutInflater.from(context);
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }


    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int i) {
        return mlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            view=getInflater().inflate(R.layout.fankuilistitem,null);
            holder=new ViewHolder();
            holder.tv_sqr=view.findViewById(R.id.tv_sqr);
            holder.tv_rw=view.findViewById(R.id.tv_rw);
            holder.tv_cx=view.findViewById(R.id.tv_cx);
            holder.tv_ys=view.findViewById(R.id.tv_ys);
            holder.tv_sj=view.findViewById(R.id.tv_sj);
            holder.tv_shenpi=view.findViewById(R.id.tv_shenpi);
//            holder.tv_time=view.findViewById(R.id.tv_time);
//            holder.tv_rgs=view.findViewById(R.id.tv_rgs);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
        if (mlist.get(i).getApplicant()!=null){
            holder.tv_sqr.setText(mlist.get(i).getApplicant());
        }else {
            holder.tv_sqr.setText("");
        }
        if (mlist.get(i).getTaskDescription()!=null){
            holder.tv_rw.setText(mlist.get(i).getTaskDescription());
        }else {
            holder.tv_rw.setText("");
        }
        if (mlist.get(i).getModels()!=null){
            holder.tv_cx.setText(mlist.get(i).getModels());
        }else {
            holder.tv_cx.setText("");
        }
        if (String.valueOf(mlist.get(i).getBudget())!=null){
            holder.tv_ys.setText(mlist.get(i).getBudget()+"");
        }else {
            holder.tv_ys.setText("");
        }
        if (String.valueOf(mlist.get(i).getActualCost())!=null){
            holder.tv_sj.setText(mlist.get(i).getActualCost()+"");
        }else {
            holder.tv_sj.setText("");
        }

//        if (mlist.get(i).getApplyDate()!=null){
//            holder.tv_time.setText(mlist.get(i).getApplyDate());
//        }else {
//            holder.tv_time.setText("");
//        }
//        if (mlist.get(i).getArtificialNums()!=null){
//            holder.tv_rgs.setText(mlist.get(i).getArtificialNums());
//        }else {
//            holder.tv_rgs.setText("");
//        }
        holder.tv_shenpi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, ShenpiResultActivity.class));
                SPUtil.putString(context,"peisongid",mlist.get(i).getDeliveryId()+"");
            }
        });
        return view;
    }


    class ViewHolder{
        TextView tv_sqr,tv_rw,tv_cx,tv_ys,tv_sj,tv_shenpi;
    }
    public void addAll(List<ShenpifankuiListBean> shenpi){
        mlist.addAll(shenpi);
        notifyDataSetChanged();
    }
}
